Enable SSI with .htaccess

Course- htaccess >

SSI stands for server side includes, these are special HTML tags which you can include in your HTML documents to call CGI scripts or other HTML content. This is particularly useful, for example to include a navigation menu in your HTML documents, it allows you to use one document to display the navigation menu in all your other documents. This saves disk space and means if you need to update the content, you only need to modify one file.

Two examples of HTML tags you would use to call SSI documents are shown below, these would be placed in your HTML document:

 

<!--#exec cgi="/cgi-bin/script.cgi"-->

This would load the CGI script 'script.cgi' which is located in the 'cgi-bin' directory.

 

<!--#include virtual="/files/document.html"-->

This example would call the HTML document 'document.html' which is located in the 'files' directory. It is important to use a relative URL, not a path or full URL.

It is likely SSI will work on your web server, but you will probably need to use '.shtml' file extensions rather than '.html'. This can be frustrating if you already have a web site setup which uses '.html' extensions. In this case, you can enable SSI by following the instructions below.

To enable SSI, create a .htaccess file following the main instructions and guidance which includes the following text:

 

AddHandler server-parsed .html

The above lines tell the Apache Web Server to allow server side includes in documents with the file extension '.html'.

To enable SSI for multiple file extensions, create a .htaccess file following the main instructions and guidance which includes the following text:

 

AddHandler server-parsed .html
AddHandler server-parsed .shtml
AddHandler server-parsed .htm

The above lines tell the Apache Web Server to allow server side includes in documents with the file extension '.html', '.shtml' and '.htm'.